package org.eoti.rei.cmp;

/**
 * The MIT License
 * <p/>
 * Copyright (c) 2009 Malachi de AElfweald (malachid@gmail.com)
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
import org.eoti.rei.NDFBrowser;
import org.eoti.io.xls.XLSReader;
import org.eoti.io.xls.XLSColumn;

import java.util.*;

public class EquityLtHComparator
	implements Comparator<Integer>
{
	protected NDFBrowser browser;
	protected XLSReader reader;
	protected XLSColumn oweCol, worthCol;

	public EquityLtHComparator(NDFBrowser browser)
	{
		this.browser = browser;
		reader = browser.getReader();
		oweCol = reader.getColumn("Foreclosure Judgement Amt");
		worthCol = reader.getColumn("Total Value");
	}

	public int compare(Integer row1, Integer row2)
	{
		double worth1 = (Double)(worthCol.getValue(row1));
		double owe1 = (Double)(oweCol.getValue(row1));
		double equity1 = worth1-owe1;
		double percent1 = (equity1/worth1)*100.0;

		double worth2 = (Double)(worthCol.getValue(row2));
		double owe2 = (Double)(oweCol.getValue(row2));
		double equity2 = worth2-owe2;
		double percent2 = (equity2/worth2)*100.0;

		return (int)(equity1-equity2);
	}
}
